import axios from "axios"
import router from "../router/router"
import store from "../store/store"
import { Loading, Message } from 'element-ui';

// loging
let loding
let startLoading = () => {
  loding=Loading.service({
        lock: true,
        spinner: "el-icon-loading",
        text: '加载中……',
        background: 'rgba(0, 0, 0, 0.7)'
    })
}

let contentType = "application/x-www-form-urlencoded; charset=UTF-8"
// 白名单
const pagePath=["/staff/login"]
// 创建实例
var service = axios.create({
    baseURL:process.env.NODE_ENV=="development"?'https://182.92.129.186:8001':'https://anfang.qdcgf.com:8001',
    timeout: 10 * 5000,
});
 

// 请求拦截器
service.interceptors.request.use(config => {
    // loding开始
    startLoading()
    config.headers['Content-Type'] = contentType
    const url=config.url.replace(config.baseURL,"")
    if(pagePath.some(wl=> url === wl)){
      return config
    }
    config.headers['Authorization'] = sessionStorage.getItem("token")
    return config;
}, error => {
    return Promise.reject(error);
});


// 响应拦截器
service.interceptors.response.use(response => {
      // 结束loading
      loding.close()
      return response.data;
}, error => {
    return Promise.reject(error);
});



export default service